﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OpenQuarters.WebQuarters.Utils;

namespace OpenQuarters.WebQuarters.Core
{
    public class JFormActionFilter<T> : ActionResult where T : class
    {
        private JFormResponse<T> _model;

        public JFormActionFilter(JFormResponse<T> model)
        {
            _model = model;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            if (CMSEnvironment.NoScript)
            {
                Oracle.Response.Redirect(Oracle.Request.UrlReferrer.ToString(), true);
            }

            context.Controller.ViewData.Model = _model.ToJSON();

            new ViewResult()
            {
                ViewName = "~/Areas/Site/Views/Shared/ServicePage.aspx",
                ViewData = context.Controller.ViewData
            }.ExecuteResult(context);
        }
    }
}
